<?php
$message=="";
$result=0;
if(isset($_POST['submit'])){
	$username=$_POST['username'];
	$password=$_POST['password'];
	$realname=$_POST['realname'];
	$phone=$_POST['phone'];
	$email=$_POST['email'];
	$ip=getIP();
	$post_data = array(
	    'method' => 'activeA2BUser',
	    'username' => $username,
	    'password' =>$password,
	    'realname' =>$realname,
		'phone' => $phone,
		'email' => $email,
		'ip' =>$ip
	);
	$result=active($post_data);
	
	if($result==1){
		$message="恭喜您帐号激活成功!";
	}elseif($result=='"001"'){
		$message="帐号密码输入错误,请重新输入.";
	}elseif($result=='"002"'){
		$message="此账号已激活,请勿重复激活.";
	}
	elseif($result=='"003"'){
		$message="此账号未开通电话服务,请联系管理员.";
	}
	echo $result.$message;
}
function active($post_data){
	$url="http://cp.netcube.com.au/api/activeA2BUser.php";
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,$url );  
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);     
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0); 
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	$output = curl_exec($ch);
	if ($output === FALSE) {
	    $output="cURL Error: " . curl_error($ch);
	}
	curl_close($ch);
	return $output;
}
function getIP()
{
	if (getenv("HTTP_CLIENT_IP"))
	$ip = getenv("HTTP_CLIENT_IP");
	else if(getenv("HTTP_X_FORWARDED_FOR"))
	$ip = getenv("HTTP_X_FORWARDED_FOR");
	else if(getenv("REMOTE_ADDR"))
	$ip = getenv("REMOTE_ADDR");
	else $ip = "Unknow";
	return $ip;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<title>无标题文档</title>
<style type="text/css">
body { background:url(img/bg.gif) no-repeat; font-family:'微软雅黑';}
td { padding:5px;}
input {font-family:'微软雅黑';}
input[type="text"],input[type="password"] { width:200px; border-radius:3px; border:1px solid #999; padding:5px; outline:0;}
input[type="text"]:focus,input[type="password"]:focus {
	background: #fff;
	box-shadow: 0px 0px 5px 0px #2e89c3;
	-webkit-box-shadow: 0px 0px 5px 0px #2e89c3;
	-moz-box-shadow: 0px 0px 5px 0px #2e89c3;
	border-color: #2e89c3;
}
table { margin-top:100px;}
input[type="submit"] {
	display: block;
	color: white;
	background: url(img/universalBtn.gif) repeat-x;
	height: 30px;
	text-decoration: none;
	font-size: 14px;
	text-align: center;
	text-shadow: 1px 1px 1px #222;
	line-height: 28px;
	border: 1px solid #c94310;
	border-radius: 2px;
	-moz-border-radius: 2px;
	-webkit-border-radius: 2px;
	padding: 0 50px;
	cursor: pointer;
	float:right;
}
input[type="submit"]:hover {
	background: url(img/universalBtnHover.gif) repeat-x;
}
h1 { color:#333; margin-top:200px; margin-left:60px;}
</style>
<script type="text/javascript">
$(document).ready(function(){
  $("#send").click(function(){
		var username = document.myform.username; 
		var password = document.myform.password; 
		var realname = document.myform.realname; 
		var phone = document.myform.phone; 
		var email = document.myform.email;
		if(username.value.length==0){ 
			document.getElementById("formmennage").innerHTML="请填写用户名!";
			username.focus(); 
			return false; 
		}else if(password.value.length==0){ 
			document.getElementById("formmennage").innerHTML="请填写密码!";
			password.focus(); 
			return false; 
		}else if(realname.value.length==0){ 
			document.getElementById("formmennage").innerHTML="请填写姓名!";
			realname.focus(); 
			return false; 
		}
		else if(phone.value.length==0){ 
			document.getElementById("formmennage").innerHTML="请填写电话!";
			phone.focus(); 
			return false; 
		}else if(email.value.length==0){ 
			document.getElementById("formmennage").innerHTML="请填写邮箱地址!";
			email.focus(); 
			return false; 
		}
	});
});

</script>
</head>

<body>
<form name="myform" method="post" action="">
  <div id="content">
  <div id="formmennage">
  <?php echo $message;?>
  </div>
  <?php if($result==1){
  	echo "<h1>".$message."</h1>";
  	
  }else{?>
  <table>
    <tr>
      <td> 用户名: </td>
      <td><input type="text" name="username" value="<?php echo $username;?>"/></td>
    </tr>
    <tr>
      <td> 密码: </td>
      <td><input type="password" name="password" /></td>
    </tr>
    <tr>
      <td> 姓名: </td>
      <td><input type="text" name="realname" value="<?php echo $realname;?>"/></td>
    </tr>
    <tr>
      <td> 电话: </td>
      <td><input type="text" name="phone" value="<?php echo $phone;?>"/></td>
    </tr>
    <tr>
      <td> 邮箱: </td>
      <td><input type="text" name="email" value="<?php echo $email;?>"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
          <input type="submit" name="submit" value="激活" id="send"/>
        </label></td>
    </tr>
  </table>
   <?php }?>
</form>
</div>
</body>
</html>